'use strict';

let fs=require('fs');

let {seq}=require('../db');

// 搜索所有的模型定义文件

function searchFiles(){
    let flies=fs.readdirSync(__dirname);
    return flies.filter(name=>{
        return name.endsWith('.js')&& name!=='index.js';
    })
}

// 注册（引入）所有的模型

function registerModels(files){
    let obj={};
    files.forEach(element => {
        let modelName =element.substring(0,element.length-3);
        obj[modelName]=require(__dirname+'/'+element);
    });
    return obj;
}

let files=searchFiles();
let obj=registerModels(files);

obj.sync=async()=>{
    return seq.sync({force:true})
}

module.exports=obj;